from openpyxl import load_workbook

from utils.get_file_abspath import get_file_abspath
from utils.log_util import logger

def read_excel_by_file(file_name,dir_name="data_files"):
    logger.info(f"开始读取文件：{dir_name}/{file_name}")
    file_path = get_file_abspath(dir_name, file_name)

    # 加载工作簿
    wb = load_workbook(filename=file_path)

    # 返回指定sheet
    return wb

def read_excel_by_sheet(file_name, sheet_name,dir_name="data_files"):
    logger.info(f"开始读取文件：{dir_name}/{file_name}:{sheet_name}")
    # 加载工作簿
    wb = read_excel_by_file(file_name,dir_name)

    # 返回指定sheet
    return wb[sheet_name]
